
package com.ygl.api.service.impl;

import java.util.Map;

import com.ygl.api.service.UserService;
import com.ygl.common.api.BaseApiService;
import com.ygl.entity.UserEntity;
import com.ygl.manage.UserServiceManage;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
public class UserServiceImpl extends BaseApiService implements UserService {
	@Autowired
	private UserServiceManage userServiceManage;

	@Override
	public Map<String, Object> regist(@RequestBody UserEntity userEntity) {
		  if(StringUtils.isEmpty(userEntity.getUserName())){
			  return setResponseParameterError("用户名称不能为空!");
		  }
		  if(StringUtils.isEmpty(userEntity.getPassword())){
			  return setResponseParameterError("密码不能为空!");
		  }
		try {
			userServiceManage.regist(userEntity);
			return setResponseSuccess();
		} catch (Exception e) {
			log.error("###regist() ERRPR:",e);
			return setResponseError("注册失败!");
		}
	}

	@Override
	public Map<String, Object> login(@RequestBody UserEntity userEntity) {
		return userServiceManage.login(userEntity);
	}

	@Override
	public Map<String, Object> getUser(@RequestParam("token") String token) {
		if (StringUtils.isEmpty(token)) {
			return setResponseParameterError("token不能为空!");
		}
		return userServiceManage.getUser(token);

	}

}
